package ysq.xyg.recovery.controller;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.recovery.model.po.RecoveryMiddleCat;
import ysq.xyg.recovery.model.vo.RecoveryMiddleCatVo;
import ysq.xyg.recovery.service.RecoveryMiddleCatService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 回收金模块-中分类controller层
 *
 * @author congcong tao
 * @date 2019-5-8 15:12:12
 */
@RestController
public class RecoveryMiddleCatController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(RecoveryMiddleCatController.class);
    @Resource
    private RecoveryMiddleCatService recoveryMiddleCatService;

    private RecoveryMiddleCat recoveryMiddleCat;

    /**
     * 分页查询
     *
     * @param recoveryMiddleCatVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author congcong tao
     * @date 2019-5-8 15:12:12
     */
    @BaseLog(module = "回收金模块",className = "中分类",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoveryMiddleCat/page",method = RequestMethod.POST)
    public ReturnEntity page(RecoveryMiddleCatVo recoveryMiddleCatVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = recoveryMiddleCatService.page(recoveryMiddleCatVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-5-8 15:12:12
     */
    @RequestMapping(value = "/recoveryMiddleCat/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/recovery/recoveryMiddleCatUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            recoveryMiddleCat = recoveryMiddleCatService.selectByPrimaryKey(id);
            view.addObject("recoveryMiddleCat", recoveryMiddleCat);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-5-8 15:12:12
     */
    @BaseLog(module = "回收金模块",className = "中分类",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoveryMiddleCat/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return recoveryMiddleCatService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param recoveryMiddleCatVo Vo对象
     * @author congcong tao
     * @date 2019-5-8 15:12:12
     */
    @BaseLog(module = "回收金模块",className = "中分类",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoveryMiddleCat/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,RecoveryMiddleCatVo recoveryMiddleCatVo){
        return recoveryMiddleCatService.addOrUpdate(recoveryMiddleCatVo,acceptCurrentUser(request));
    }

    /**
     * 根据id查询json数据
     * @param id
     * @author congcong tao
     * @date 2019/7/8 16:56
     */
    @RequestMapping(value = "/recoveryMiddleCat/getRecoveryMiddleCatById",method = RequestMethod.POST)
    public ReturnEntity getRecoverySmallCatById(String id){
        RecoveryMiddleCat recoveryMiddle = recoveryMiddleCatService.selectByPrimaryKey(id);
        return new ReturnEntity(recoveryMiddle);
    }

    @RequestMapping(value = "/recoveryMiddleCat/acceptSelect",method = RequestMethod.POST)
    public ReturnEntity acceptSelect(String code){
        return recoveryMiddleCatService.acceptSelect(code);
    }
}